package org.zjut.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.zjut.db.LearnerCourseAttrDataBase;
import org.zjut.util.CommonUtil;

import javax.servlet.http.HttpServletRequest;

import static org.zjut.util.CommonUtil.getBodyRequest;

/**
 * @author Rising
 * @date 2017/8/22
 * @des
 */
@Controller
public class LearnerController {
    @Autowired
    LearnerCourseAttrDataBase learnerCourseAttrDataBase;


//    /**
//     * 添加学习者属性值
//     * @param request
//     * @return
//     */
//    @RequestMapping(value="/addLeanerAttr", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
//    @ResponseBody
//    public String addLeanerAttr(HttpServletRequest request){
//        JSONObject params = JSON.parseObject(getBodyRequest(request));
//        if(request==null){
//            return JSON.toJSONString(CommonUtil.setErrorInfo("请求参数有问题，请注意检查"));
//        }
//        try{
//            return JSON.toJSONString(learnerCourseAttrDataBase.addLeanerAttr(params));
//        }catch (Exception e){
//            return JSON.toJSONString(CommonUtil.setErrorInfo("插入失败"));
//        }
//    }
//
//    /**
//     * 获取学习者属性值
//     * @param request
//     * @return
//     */
//    @RequestMapping(value="/getLeanerAttr", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
//    @ResponseBody
//    public String getLeanerAttr(HttpServletRequest request){
//        JSONObject params = JSON.parseObject(getBodyRequest(request));
//        if(request==null){
//            return JSON.toJSONString(CommonUtil.setErrorInfo("请求参数有问题，请注意检查"));
//        }
//        return JSON.toJSONString(learnerCourseAttrDataBase.getLeanerAttr(params));
//    }
//
//    /**
//     * 清空学习者属性值
//     * @param request
//     * @return
//     */
//    @RequestMapping(value="/delLeanerAttr", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
//    @ResponseBody
//    public String delLeanerAttr(HttpServletRequest request){
//        JSONObject params = JSON.parseObject(getBodyRequest(request));
//        if(request==null){
//            return JSON.toJSONString(CommonUtil.setErrorInfo("请求参数有问题，请注意检查"));
//        }
//        try{
//            return JSON.toJSONString(learnerCourseAttrDataBase.delLeanerAttr(params));
//        }catch (Exception e){
//            return JSON.toJSONString(CommonUtil.setErrorInfo("删除失败"));
//        }
//    }
//
//    /**
//     * 修改学习者属性值
//     * @param request
//     * @return
//     */
//    @RequestMapping(value="/editLeanerAttr", method = RequestMethod.POST,produces = "application/json;charset=utf-8")
//    @ResponseBody
//    public String editLeanerAttr(HttpServletRequest request){
//        JSONObject params = JSON.parseObject(getBodyRequest(request));
//        if(request==null){
//            return JSON.toJSONString(CommonUtil.setErrorInfo("请求参数有问题，请注意检查"));
//        }
//        try{
//            return JSON.toJSONString(learnerCourseAttrDataBase.editLeanerAttr(params));
//        }catch (Exception e){
//            return JSON.toJSONString(CommonUtil.setErrorInfo("修改失败"));
//        }
//    }
}
